package offer;

import java.util.HashMap;
import java.util.Map;

public class offer48 {
}
class Solution48 {
    public  static int lengthOfLongestSubstring(String s) {
//        dp[i]表示str的长度为i时不包含重复字符的子字符串长度为dp[i]
//        当s[i]前面没有重复字符时dp[i] = dp[i-1]+1
//        当前面有重复字符的时候dp[i]=1 str从当前开始查看是否包含重复字符
//        dp[0] = 1;
        char [] c = s.toCharArray();
        int []dp = new int[c.length];
        if(s.length()==0||s.length()==1)
        {
            return s.length();
        }
        dp[0] = 1;
        int start =0;
        int max =1;
        for (int i = 1; i < c.length; i++) {
            if(noSame(c,start,i)==i)//如果前面的字符没有和当前字符相同则为真
            {
                dp[i] = dp[i-1]+1;
            }else
            {
                dp[i] =i-noSame(c,start,i);
                start = noSame(c,start,i) ;
            }
            max = Math.max(dp[i],max);
        }
        return max;

    }

    private  static  int  noSame(char[] c, int start,int end) {
        char temp = c[end];
        int tmp=end;
        for (int  i = start; i <end; i++) {
            if(c[i]==temp)
            {
                tmp = i;

            }
        }
        return tmp;
    }

    public static void main(String[] args) {
        String s ="bbbbb";
        lengthOfLongestSubstring(s);
    }
}